#include "StageLayer.h"
#include <stdlib.h>

using namespace cocos2d;

int StageLayer::totalStages()
{
    return 5;
}

CCScene *StageLayer::scene()
{
    CCScene *scene = CCScene::create();
    StageLayer *layer = StageLayer::create();
    
    scene->addChild(layer);
 
    return scene;
}

bool StageLayer::init()
{
    if(!CCLayer::init())
    {
        return false;
    }
    
    CCMenu *stages = CCMenu::create();
    int i;
    for (i = 0; i < this->totalStages(); i++)
    {
        char a[10];
        sprintf(a, "%d", i);
		//CCLabelTTF *label = CCLabelTTF::create(a,"", 25)
        CCMenuItemFont *stageMenuItem = CCMenuItemFont::create(a, 
                                                                       this,
                                                                       menu_selector(StageLayer::selectStage));
        stages->addChild(stageMenuItem);
    }
    stages->alignItemsVertically();
    this->addChild(stages);
    
    return true;
}

void StageLayer::selectStage(CCObject *sender)
{
    CCMenuItemLabel *item = (CCMenuItemFont *)sender;
    CCLabelTTF *stageLabel = (CCLabelTTF *)item->getLabel();
	CCLog("select stage---- %s", stageLabel->getString()); 
	int stage = (int)(stageLabel->getString()[0] - '0');
	CCLog("stage at StageLayer-------%d", stage);
    CCScene *scene = GameScene::sceneWithStage(stage);
    CCDirector::sharedDirector()->replaceScene(scene);
}